package com.wc.alorithm_luogu.P5728;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/4/21 11:26
 * @description https://www.luogu.com.cn/problem/P5728
 * 旗鼓相当的对手
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        // 存储所有人的成绩
        int[][] scores = new int[n][3];

        // 存储答案
        int ans = 0;

        // 当前分叉
        int subScore;

        //总分差
        int totalSubScore;

        // 是否是分差都小于5
        boolean flag;

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < 3; j++) {
                scores[i][j] = sc.nextInt();
            }

            for (int j = 0; j < i; j++) {
                flag = true;
                totalSubScore = 0;
                for (int k = 0; k < 3; k++) {
                    subScore = scores[i][k] - scores[j][k];
                    totalSubScore += subScore;
                    if (Math.abs(subScore) > 5) {
                        flag = false;
                        break;
                    }
                }
                if (flag && Math.abs(totalSubScore) <= 10) {
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }
}
